const db = require('../../db')

let bookQuery = {
    config: {
        description: '书本查询',
        cors: {
            origin: ['*'],
            additionalHeaders: ['cache-control', 'x-requested-with']
        }
    },
    method: 'post',
    path: '/book/query',
    handler: async (request, h) => {

        let request_body = request.payload
        let promise = function () {
            return new Promise((resolve, reject) => {
                db.book.find((err, docs) => {
                    if (err) {
                        reject(err)
                    }
                    resolve(docs)
                })
            })
        }

        return await promise()
    }
}

module.exports = bookQuery